package com.heima.media.controller;


import com.heima.common.dto.PageResponseResult;
import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.ChannelDto;
import com.heima.media.entity.WmChannel;
import com.heima.media.service.IWmChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/channel")
@Api(tags = "频道管理API")
public class ChannelController {

    @Autowired
    private IWmChannelService wmChannelService;

    //频道分页列表根据名称模糊查询
    @PostMapping("/list")
    @ApiOperation(value = "根据名称模糊查询分页列表", notes = "author:mcm")  // value指名称  notes 备注
    @ApiImplicitParam(name = "dto", value = "查询对象", required = true, dataType = "ChannelDto")
    public PageResponseResult listByName(@RequestBody ChannelDto channelDto){

        return wmChannelService.listByName(channelDto);
    }

    //保存频道
    @PostMapping
    public ResponseResult saveChannel(@RequestBody WmChannel wmChannel){

        return wmChannelService.saveChannel(wmChannel);
    }

    /**
     * 查询频道列表
     * @return
     */
    @GetMapping("/channels")
    public ResponseResult channels(){
        List<WmChannel> wmChannelList = wmChannelService.list();
        return ResponseResult.okResult(wmChannelList);
    }

}
